package com.example.tcpmaster;

/**
 * Created by lianxiang on 2017/9/6.
 * TCP连接参数配置
 */

public class TcpConnectOptions {
    private  Builder builder ;

    public TcpConnectOptions(Builder builder) {
        this.builder = builder;
    }

    public int getTimeOut(){
        return  builder.timeOut;
    }

    public int getReConnectTime(){
        return  builder.reConnectTime;
    }

    public String getHostIP(){
        return builder.hostIP;
    }

    public int getPort(){
        return  builder.port;
    }

    public static class Builder{
        int timeOut = 10 * 1000;
        int reConnectTime =  5 * 1000;
        String hostIP;
        int port;
        /**
         * 设置超时时间
         * @param milliSeconds
         * @return
         */
        public Builder timeOut(int milliSeconds){
            this.timeOut = milliSeconds;
            return this;
        }


        /**
         * 重新发起连接的时间
         * @param milliSeconds
         * @return
         */
        public Builder reConnectTime(int milliSeconds){
            this.reConnectTime  = milliSeconds;
            return this;
        }


        /**
         * 主机IP
         * @param hostIP
         * @return
         */
        public Builder hostIP(String hostIP){
            this.hostIP  = hostIP;
            return this;
        }

        /**
         * 主机端口
         * @param port
         * @return
         */
        public Builder port(int port){
            this.port  = port;
            return this;
        }


        public Builder build(){
            return this;
        }

        public TcpConnectOptions create(){
            return new TcpConnectOptions(this);
        }
    }
}
